package com.itboye.ihomebank.responsitory;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.reflect.TypeToken;
import com.itboye.ihomebank.adapter.QuBean;
import com.itboye.ihomebank.base.BaseNetRepository;
import com.itboye.ihomebank.base.ICompleteListener;
import com.itboye.ihomebank.bean.HouseBean;
import com.itboye.ihomebank.bean.HouseDetailBean;
import com.itboye.ihomebank.bean.HouseListBean;
import com.itboye.ihomebank.bean.HouseListBeanCopy;
import com.itboye.ihomebank.bean.HouseZiDianBean;
import com.itboye.ihomebank.bean.QianYueManageBean;
import com.itboye.ihomebank.bean.QuYuBean;
import com.itboye.ihomebank.bean.WoDeFangYuanBean;
import com.itboye.ihomebank.bean.WoDeQiuZuBean;
import com.itboye.ihomebank.bean.ZuKeBean;
import com.itboye.ihomebank.interfaces.IHouseInterface;
import com.itboye.ihomebank.net.BaseErrorListener;
import com.itboye.ihomebank.net.BaseSuccessReqListener;
import com.itboye.ihomebank.net.ByJsonRequest.Builder;

/***
 * 请求网络类
 * 
 * @author admin
 * 
 */
public class HouseRepository extends BaseNetRepository implements
		IHouseInterface<HouseBean> {
	String api = "100";
	String colletionKey = "BY_Favorites_add";// 用户登录
	String queryHouse = "BY_House_query";// 房源查询
	String queryHouseByCityCode = "BY_House_getQueryParams";// 多级数据返回区、小区、
	String houseDetail = "BY_House_detail";// 房源详情
	String qianYueShenQing = "BY_Rent_rent";// 签约申请
	String yuYueKanFang = "BY_Rent_rentview";// 预约看房
	String woDeFaBu = "BY_House_lend";// 我的发布
	String shangjia = "BY_House_onshelf";// 上架
	String xiajia = "BY_House_offshelf";// 下架

	String quyuLieBiao = "BY_House_getAreaList";// 获取房源下级区域列表
	String zukelist = "BY_Rent_rentapply";// 查看租客申请列表
	String renZhengFangYuan = "BY_House_verify";// 房源审核
	String xuanZuKe = "BY_Rent_select";// 选择某个租客
	String woDeFangYuan = "BY_Rent_query";// 我的房源
	String houseZiDian = "BY_House_getDtreeList";// 房源字典

	String qianYueGuanLi = "BY_Contract_contractManage";// 签约管理

	String rentQueryview = "BY_Rent_queryview";// 房客看房申请列表
	String hotTag="BY_House_hotKey";//获取热门所搜标签
	public HouseRepository(ICompleteListener iCompleteListener) {
		super(iCompleteListener);
	}

	@Override
	public void getHouseAdd(String uid, String imgs, String community_code,
			int rent_type, String contact_name, String contact_phone, int rent,
			int size, String unit, int house_floor, int floors,
			String house_decoration, String house_pay, String house_dir,
			String address) {
		// TODO Auto-generated method stub

	}

	/**
	 * 收藏房源
	 */
	@Override
	public void collection(String uid, String fType, String favoriteId,
			int status) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("f_type", fType);
		map.put("favorite_id", favoriteId);
		map.put("status", status);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(colletionKey, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void queryHouse(String cityCode, String searchText,
			String areaOrZone, String rental, String aceage, String houseType,
			String rentType, String decoration, String oritation, String floor,
			String source, String houseTag, String order, String perPage,
			String currentPage) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<HouseListBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("city", cityCode);
		if (!searchText.equals(""))
			map.put("search_text", searchText);
		if (!areaOrZone.equals(""))
			map.put("area_or_zone", areaOrZone);
		if (!rental.equals(""))
			map.put("rental", rental);
		if (!aceage.equals(""))
			map.put("acreage", aceage);
		if (!houseType.equals(""))
			map.put("house_type", houseType);
		if (!rentType.equals(""))
			map.put("rent_type", rentType);
		if (!rental.equals(""))
			map.put("decoration", decoration);
		if (!oritation.equals(""))
			map.put("orientation", oritation);
		if (!floor.equals(""))
			map.put("floor", floor);
		if (!source.equals(""))
			map.put("source", source);
		if (!houseTag.equals(""))
			map.put("house_tag", houseTag);
		if (!order.equals(""))
			map.put("order", order);
		if (!perPage.equals(""))
			map.put("per_page", perPage);
		if (!currentPage.equals(""))
			map.put("current_page", currentPage);
		(new Builder<HouseListBean>())
				.setTypeVerParamsAndReturnClass(queryHouse, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<HouseListBean>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void getAreaByCityCode(String cityCode) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<HouseListBeanCopy>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("city", cityCode);
		(new Builder<HouseListBeanCopy>())
				.setTypeVerParamsAndReturnClass(queryHouseByCityCode, apiVer,
						map, type)
				.requestListener(
						new BaseSuccessReqListener<HouseListBeanCopy>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void queryHouseDetail(String houseNo, String uid) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<HouseDetailBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("house_no", houseNo);
		map.put("uid", uid);
		(new Builder<HouseDetailBean>())
				.setTypeVerParamsAndReturnClass(houseDetail, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<HouseDetailBean>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void shenQingQianYue(String uid, String houseNo, String remark,
			String status) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();

		map.put("house_no", houseNo);
		map.put("uid", uid);
		map.put("remark", remark);
		map.put("status", status);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(qianYueShenQing, apiVer, map,
						type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void yuYueKanFang(String uid, String houseNo, String mark,
			 String startT, String endT,String status) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();

		map.put("house_no", houseNo);
		map.put("uid", uid);
		map.put("mark", mark);
		map.put("status", status);
		map.put("starttime", startT);
		map.put("endtime", endT);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(yuYueKanFang, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void getWoDeFaBu(String uid) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<List<WoDeFangYuanBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();

		map.put("uid", uid);
		(new Builder<List<WoDeFangYuanBean>>())
				.setTypeVerParamsAndReturnClass(woDeFaBu, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<List<WoDeFangYuanBean>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void xiajia(String uid, String houseNo) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();

		map.put("uid", uid);
		map.put("house_no", houseNo);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(xiajia, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void shangjia(String uid, String houseNo) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();

		map.put("uid", uid);
		map.put("house_no", houseNo);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(shangjia, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	/**
	 * 房源区域列表
	 */
	@Override
	public void getQuyuLieBiao(String area_code) {
		Type type = new TypeToken<List<QuYuBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();

		if (!area_code.equals("")) {
			map.put("area_code", area_code);
		}

		(new Builder<List<QuYuBean>>())
				.setTypeVerParamsAndReturnClass(quyuLieBiao, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<List<QuYuBean>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 房源区域列表
	 */
	@Override
	public void getQuyuLieBiao02(String area_code) {
		Type type = new TypeToken<List<QuBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();

		if (!area_code.equals("")) {
			map.put("area_code", area_code);
		}

		(new Builder<List<QuBean>>())
				.setTypeVerParamsAndReturnClass(quyuLieBiao, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<List<QuBean>>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	@Override
	public void xuanZuKe(String uid,String ownerUid, String houseNo, String status) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();

		map.put("uid", uid);
		map.put("owner_uid", ownerUid);
		map.put("house_no", houseNo);
		map.put("status", status);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(xuanZuKe, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void getZuKeList(String houseNo) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<List<ZuKeBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("house_no", houseNo);
		(new Builder<List<ZuKeBean>>())
				.setTypeVerParamsAndReturnClass(zukelist, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<List<ZuKeBean>>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void fangYuanRenZheng(String uid, String houseNo, String pass,
			String msg) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();

		map.put("uid", uid);
		map.put("house_no", houseNo);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(renZhengFangYuan, apiVer, map,
						type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void getMyRentHouse(String uid) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<List<WoDeFangYuanBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();

		map.put("uid", uid);
		(new Builder<List<WoDeFangYuanBean>>())
				.setTypeVerParamsAndReturnClass(woDeFangYuan, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<List<WoDeFangYuanBean>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	/**
	 * 房源数据字典
	 */
	@Override
	public void houseZiDian(String city_code) {
		Type type = new TypeToken<HouseZiDianBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();

		if (city_code != null) {
			map.put("city_code", city_code);
		}

		(new Builder<HouseZiDianBean>())
				.setTypeVerParamsAndReturnClass(houseZiDian, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<HouseZiDianBean>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	@Override
	public void qianYueGuanLi(String uid, String sort) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<List<QianYueManageBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();

		map.put("uid", uid);
		map.put("sort", sort);
		(new Builder<List<QianYueManageBean>>())
				.setTypeVerParamsAndReturnClass(qianYueGuanLi, apiVer, map,
						type)
				.requestListener(
						new BaseSuccessReqListener<List<QianYueManageBean>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 我的求租（房客看房申请列表）
	 */
	@Override
	public void getQiuZu(String uid) {
		Type type = new TypeToken<List<WoDeQiuZuBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);

		(new Builder<List<WoDeQiuZuBean>>())
				.setTypeVerParamsAndReturnClass(rentQueryview, apiVer, map,
						type)
				.requestListener(
						new BaseSuccessReqListener<List<WoDeQiuZuBean>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	@Override
	public void getHotTag(String cityCode) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<List<String>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("city", cityCode);
		map.put("max", 10);
		(new Builder<List<String>>())
				.setTypeVerParamsAndReturnClass(hotTag, apiVer, map,
						type)
				.requestListener(
						new BaseSuccessReqListener<List<String>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

}
